import User from "../entities/User";
import Operator from "./Operator";
import {RC} from "../config/RC";


class CheckUserIdExistOperator extends Operator{
    public async execute(): Promise<RC> {
        const user_id: string = this.args.getProperty('userId');
        const receiver_id:string = this.args.getProperty('receiver_id');
        
        if(receiver_id!=null){
            const isExist = await User.CheckUserIdExist(receiver_id);
            if (!isExist) {
                    return RC.RECEIVERID_NOTEXIST;
            }
        } 
        
        if(user_id!=null)
        {
            try {
                const isExist = await User.CheckUserIdExist(user_id);
                if (isExist) {
                    return RC.SUCCESS;
                } else {
                    return RC.USERID_NOTEXIST;
                }
            } catch (error) {
                // 处理异常情况
                console.error('Error checking user existence:', error);
                return RC.INTERNAL_ERROR;
            }
        }else
        {
            return RC.INVALID_ARGUMENT;
        }        
    }
}

export default CheckUserIdExistOperator;